package cn.edu.dgut.experiment3.controller;

import cn.edu.dgut.experiment3.dao.RegionDao;
import cn.edu.dgut.experiment3.pojo.Region;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

@Controller
public class RegionController {

    @Autowired
    private RegionDao regionDao;

    @RequestMapping("/index")
    public String index( HttpServletRequest request ){
        request.getSession().setAttribute("virusList", regionDao.dataList);
        request.getSession().setAttribute("localDateTime", LocalDateTime.now());
        return "index.html";
    }

    @RequestMapping("/search")
    public String searchByCountry( HttpServletRequest request ){
        String country = request.getParameter("country");
        List<Region> searchList = new ArrayList();
        searchList = regionDao.getDataByCountry(country);
        request.getSession().setAttribute("searchList",searchList);
        return "search.html";
    }
}